using System;
using System.Windows.Forms;
using CodePlex.DnD4eCampaignManager.Presentation.PresenterInterfaces;
using CodePlex.DnD4eCampaignManager.Presentation.ViewInterfaces;

namespace CodePlex.DnD4eCampaignManager.ControlLibrary
{
    public partial class DefensesControl : UserControl, IDefensesView
    {
        private IDefensesPresenter _presenter;

        public DefensesControl()
        {
            InitializeComponent();
        }

        public int ArmorClass
        {
            get
            {
                return Convert.ToInt32(ArmorClassTextbox.Value);
                ;
            }
            set { ArmorClassTextbox.Value = value; }
        }

        public int ArmorClassAbilityBonus
        {
            set { ACAbilityTextbox.Text = value.ToString(); }
        }

        public int ArmorClassBonusFromArmor
        {
            set { ACArmorTextbox.Text = value.ToString(); }
        }

        public int ArmorClassClassBonus
        {
            set { ACClassTextbox.Text = value.ToString(); }
        }

        public int BaseDefense
        {
            set { BaseDefenseLabel.Text = value.ToString(); }
        }

        public int FortitudeDefense
        {
            get { return Convert.ToInt32(FortitudeDefenseTextbox.Value); }
            set { FortitudeDefenseTextbox.Value = value; }
        }

        public int FortitudeDefenseAbilityBonus
        {
            set { throw new NotImplementedException(); }
        }

        public int FortitudeDefenseBonusFromItem
        {
            set { throw new NotImplementedException(); }
        }

        public int FortitudeDefenseClassBonus
        {
            set { throw new NotImplementedException(); }
        }

        public IDefensesPresenter Presenter
        {
            private get
            {
                if ( _presenter == null )
                {
                    throw new InvalidOperationException("The Presenter cannot be used before it is initialized.");
                }
                return _presenter;
            }
            set { _presenter = value; }
        }

        public int ReflexDefense
        {
            get { return Convert.ToInt32(ReflexDefenseTextbox.Value); }
            set { ReflexDefenseTextbox.Text = value.ToString(); }
        }

        public int ReflexDefenseAbilityBonus
        {
            set { throw new NotImplementedException(); }
        }

        public int ReflexDefenseBonusFromItem
        {
            set { throw new NotImplementedException(); }
        }

        public int ReflexDefenseClassBonus
        {
            set { throw new NotImplementedException(); }
        }

        public int WillpowerDefense
        {
            get { return Convert.ToInt32(WillpowerDefenseTextbox.Value); }
            set { WillpowerDefenseTextbox.Text = value.ToString(); }
        }

        public int WillpowerDefenseAbilityBonus
        {
            set { throw new NotImplementedException(); }
        }

        public int WillpowerDefenseBonusFromItem
        {
            set { throw new NotImplementedException(); }
        }

        public int WillpowerDefenseClassBonus
        {
            set { throw new NotImplementedException(); }
        }

        private void ArmorClassTextbox_Enter(object sender, EventArgs e)
        {
            if ( ArmorClassTextbox.Text.Length > 0 )
            {
                ArmorClassTextbox.Select();
                ArmorClassTextbox.Select(0, ArmorClassTextbox.Value.ToString().Length);
            }
        }
    }
}